export default {
  data() {
    return {
      loading: false,
      list: [],
      handleDialog: null
    };
  },
  created() {
    this.loadData();
  },
  mounted() {
    this.handleDialog = this.$refs["handleDialog"];
  },
  methods: {
    loadData() {
      this.loading = true;
      //todo reset the page number to one when you click the query button
      this.axios(this.apiSetting)
        .then(res => {
          this.list = []
          //todo there may be a bug here
          if (res === false) return;
          if (this.customList) {
            this.$emit("processData", res, res => {
              this.list = res;
            });
          } else {
            this.list = Array.isArray(res.list)
              ? res.list
              : Array.isArray(res)
                ? res
                : [];
          }
          if (this.pagination)
            //data table with pagination
            this.total = res.total || 0;
          this.$emit("after-load-data");
        })
        .finally(() => {
          this.loading = false;
        });
    }
  }
};
